package com.imooc.dataobject.mapper;

import com.imooc.dataobject.ProductCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * FileName: ProductCategoryMapper.java
 * Description: TODO
 *
 * @author HuangRI(874668739 @ qq.com)
 * @version 1.0
 * @date 2021/1/5
 */
public interface ProductCategoryMapper {

    @Insert("insert into product_category(category_name, category_type) values (#{category_name, jdbcType=VARCHAR}, #{category_type, jdbcType=INTEGER})")
    int insertByMap(Map<String, Object> map);

    @Insert("insert into product_category(category_name, category_type) values (#{categoryName, jdbcType=VARCHAR}, #{categoryType, jdbcType=INTEGER})")
    int insertByProductCategory(ProductCategory productCategory);

    @Select("select * from product_category where category_type=#{type}")
    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "category_type", property = "categoryType"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),

    })
    ProductCategory findByCategoryType(Integer type);

    ProductCategory selectByCategoryType(Integer type);

    @Select("select * from product_category where category_name=#{name}")
    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "category_type", property = "categoryType"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),

    })
    List<ProductCategory> findByCategoryName(String name);

    // 如果更新的时候报找不到参数，则在方法参数前面加上@Param
    @Update("update product_category set category_name=#{name} where category_type=#{type}")
    int updateByCategoryType(/*@Param("type")*/ Integer type, String name);

    // 如果更新的时候报找不到参数，则在方法参数前面加上@Param
    @Update("update product_category set category_name=#{categoryName} where category_type=#{categoryType}")
    int updateByProductCategory(ProductCategory productCategory);

    @Delete("delete from product_category where category_type=#{type}")
    int deleteByCategoryType(Integer type);
}
